<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:pe="http://primefaces.org/ui/extensions">
    <h:head>
        <title>#{bundle.jv}</title>
        <link href="./resources/css/default.css" rel="stylesheet" type="text/css" />
    </h:head>
    <h:body>
        <ui:composition>
            <h:form>
                
                <script type="text/javascript">  
                    
                   var doInitForm=false;
                   function setDoInitForm(st) {doInitForm=st;}
                   
                   function handleCompleteSaving(xhr, status, args) {  
                      /*
                        
                         if(args.validationFailed || !args.success) {
                            
                        }else 
                            setTimeout(function() {
                                if (doInitForm==true) btnNewJV.jq.click();  
                            }, 3000);
                            */
                    }
                </script>  
                
                <p:toolbar>
                    <p:toolbarGroup align="left">
                        <p:commandButton value="#{bundle.btnNew}" icon="ui-icon-document" action="#{jvBean.newData()}" 
                                         update="displayJv, btnPostJV, btnSaveJV" process="@this"
                                         widgetVar="btnNewJV" oncomplete="setDoInitForm(false);"
                                         rendered="#{menuBean.cekButtonAccess(501,'INS;')}">
                            <pe:resetEditableValues for="displayJv"/>  
                        </p:commandButton>  
                        <p:commandButton value="#{bundle.btnSave}" icon="ui-icon-disk"
                                         rendered="#{menuBean.cekButtonAccess(501,'INS;')}"
                                         id="btnSaveJV"
                                         oncomplete="setDoInitForm(true); handleCompleteSaving(xhr, status, args);"
                                         action="#{jvBean.trySave()}" disabled="#{!jvBean.editMode}" update="displayJv, btnPostJV, @this" >
                        </p:commandButton> 
                        
                        <p:commandButton value="#{bundle.btnPost}" icon="ui-icon-disk"
                                         rendered="#{menuBean.cekButtonAccess(501,'INS;')}"
                                         id="btnPostJV"
                                         action="#{jvBean.posting()}" disabled="#{jvBean.posted}" update="@this" >
                        </p:commandButton> 
                        
                    </p:toolbarGroup>
                    <p:toolbarGroup align="right">
                        <p:commandButton id="doNothingJV" type="button" value="" style="width: 0px; height: 0px;"/> 
                        <p:defaultCommand target="doNothingJV"/> 
                    </p:toolbarGroup>
                </p:toolbar>
                
                <h:panelGrid id="displayJv" styleClass="addELIT" cellpadding="0" border="0" >
                    <h:panelGrid columns="2" rowClasses="panelGridId" >
                        <p:panel >
                             <h:panelGrid columns="3" border="0" cellpadding="0" cellspacing="5">
                                 
                                <h:outputLabel value= "#{bundle.jvNo}" /><h:outputLabel value= ":" />
                                <h:outputText value="#{jvBean.jv.jvNo}" />

                                <h:outputLabel value= "#{bundle.date}" /><h:outputLabel value= ":" />
                                <h:outputText value="#{jvBean.jv.jvDate}" />

                                <h:outputLabel value= "#{bundle.description}" /><h:outputLabel value= ":" />
                                <p:inputText value="#{jvBean.jv.description}" style="width: 620px;" disabled="#{!jvBean.editMode}" />
                                
                                <h:outputLabel value= "#{bundle.branch}" /><h:outputLabel value= ":" />
                                <p:selectOneMenu value="#{jvBean.jv.branchId}" style="width: 250px;" disabled="true">
                                    <f:selectItems value="#{jvBean.avblBranch}"/>
                                </p:selectOneMenu>
                                
                            </h:panelGrid>
                            
                            <br/>
                            <pe:masterDetail id="jvMD" selectLevelListener="#{selectLevelListener.handleNavigation}" style="width: 700px;">
                                <pe:masterDetailLevel level="1" levelLabel="#{bundle.jvdet}">
                                    <p:outputPanel autoUpdate="true">
                                        <p:dataTable id="dtJvdetails" var="jvdet" value="#{jvBean.jv.jvdets}" rowIndexVar="noUrut2">
                                            <p:column style="width: 11px;">
                                                <f:facet name="header">No</f:facet>
                                                    <h:outputText value="#{noUrut2+1}" styleClass="numPos" >
                                                        <f:convertNumber groupingUsed="true"/>
                                                    </h:outputText>
                                            </p:column>
                                            
                                            <p:column style="width: width:auto">
                                                <f:facet name="header">#{bundle.glaccnt}</f:facet>
                                                <h:outputText value="#{jvBean.selectItemValueOf(jvdet.glaccntId)}" style="width:100px;" />
                                            </p:column>
                                            
                                            <p:column style="width: 80px;">
                                                <f:facet name="header">#{bundle.debet}</f:facet>
                                                <h:outputText value="#{jvdet.debit}" styleClass="numPos" >
                                                    <f:convertNumber groupingUsed="true"/>
                                                </h:outputText>
                                            </p:column>
                                            
                                            <p:column style="width: 80px;">
                                                <f:facet name="header">#{bundle.credit}</f:facet>
                                                <h:outputText value="#{jvdet.credit}" styleClass="numPos" >
                                                    <f:convertNumber groupingUsed="true"/>
                                                </h:outputText>
                                            </p:column>
                                            
                                            <p:column style="width:auto">
                                                <f:facet name="header">#{bundle.description}</f:facet>
                                                <h:outputText value="#{jvdet.description}"  />
                                            </p:column>

                                            <p:column style="width:90px" >
                                                <f:facet name="header">Actions</f:facet>
                                                <p:commandLink value="Add" actionListener="#{jvBean.newDetail()}" disabled="#{!jvBean.editMode}" >
                                                    <pe:selectDetailLevel contextValue="#{null}" preserveInputs="false"/>
                                                </p:commandLink><p:spacer width="2"/>

                                                <p:commandLink value="Edit" actionListener="#{jvBean.editDetail(jvdet)}" disabled="#{!jvBean.editMode or jvdet.glaccntId==null}" >
                                                    <pe:selectDetailLevel contextValue="#{jvdet}" preserveInputs="false"/>
                                                </p:commandLink><p:spacer width="2"/>

                                                <p:commandLink value="Del" actionListener="#{jvBean.handleRemoveDetail}" disabled="#{!jvBean.editMode or jvdet.glaccntId==null}" >
                                                    <p:collector value="#{jvdet}" removeFrom="#{jvBean.jv.jvdets}" />  
                                                </p:commandLink>
                                            </p:column>
                                            
                                            <p:columnGroup type="footer">  
                                                <p:row>  
                                                    <p:column colspan="2" footerText="Totals:"  style="text-align:right"  />  
                                                    <p:column style="text-align:right" footerText="#{jvBean.sumDebet}" />
                                                    <p:column style="text-align:right" footerText="#{jvBean.sumCredit}" />
                                                        
                                                    <p:column footerText="" />  
                                                    <p:column footerText="" />  
                                                </p:row>  
                                            </p:columnGroup>  
                                        </p:dataTable>
                                    </p:outputPanel>
                                </pe:masterDetailLevel>
                                
                                
                                <pe:masterDetailLevel level="2" levelLabel="Add/edit" contextVar="jvdet" >
                                    <h:panelGrid id="frmJV" columns="3" border="0" cellpadding="0" cellspacing="10" >
                                        <h:outputLabel value= "#{bundle.glaccnt}" /><h:outputLabel value=":"/>
<!--                                        <p:selectOneMenu value="#{jvBean.unsaveGL}" style="width: 170px;" var="glaccnt" converter="glaccnt">
                                            <f:selectItem rendered="#{jvBean.unsaveGL!=null}" itemLabel="#{jvBean.unsaveGL.accountName}" itemValue="#{jvBean.unsaveGL}" />
                                            <f:selectItems value="#{jvBean.availableGL}" var="gl" itemLabel="#{gl.accountName}" itemValue="#{gl}"/>
                                            <p:column>#{glaccnt.accountNo}</p:column>
                                            <p:column>#{glaccnt.accountName}</p:column>
                                        </p:selectOneMenu>-->
                                        
                                        <p:autoComplete value="#{jvBean.unsaveGL}" completeMethod="#{jvBean.completeGL}" size="50"
                                            var="acc" itemLabel="#{acc.accountNo} #{acc.accountName}" itemValue="#{acc}" converter="glaccnt" forceSelection="true"
                                            maxResults="10" minQueryLength="3" dropdown="true" >
                                            <p:column width="50" >#{acc.accountNo}</p:column>  
                                            <p:column width="200">#{acc.accountName}</p:column>  
                                        </p:autoComplete>
                                        
                                        <h:outputLabel value= "#{bundle.debet}" /><h:outputLabel value=":"/>
                                        <h:panelGrid columns="2" cellpadding="0" cellspacing="0">
                                            <pe:inputNumber decimalSeparator="." thousandSeparator="," maxValue="99999999999999999999.99" minValue="0" 
                                                styleClass="money" value="#{jvBean.unsaveDetail.debit}" style="width: 150px;"
                                                id="jvdetDebet" label="#{bundle.debet}"
                                                requiredMessage="#{bundle.debet} #{bundle.requiredInput}">
                                                <p:ajax event="blur" update="msgjvdetDebet, jvdetCredit" process="@this" listener="#{jvBean.initCredit()}" partialSubmit="false"/> 
                                                <f:convertNumber groupingUsed="true" />
                                            </pe:inputNumber>
                                            <p:message id="msgjvdetDebet" for="jvdetDebet" display="icon" />
                                        </h:panelGrid>
                                        
                                        <h:outputLabel value= "#{bundle.credit}" /><h:outputLabel value=":"/>
                                        <h:panelGrid columns="2" cellpadding="0" cellspacing="0">
                                            <pe:inputNumber decimalSeparator="." thousandSeparator="," maxValue="99999999999999999999.99" minValue="0" 
                                                styleClass="money" value="#{jvBean.unsaveDetail.credit}" style="width: 150px;"
                                                id="jvdetCredit" label="#{bundle.credit}" 
                                                requiredMessage="#{bundle.credit} #{bundle.requiredInput}">
                                                <p:ajax event="blur" update="msgjvdetCredit, jvdetDebet" listener="#{jvBean.initDebit()}" partialSubmit="false"/> 
                                                <f:convertNumber groupingUsed="true" />
                                            </pe:inputNumber>
                                            <p:message id="msgjvdetCredit" for="jvdetCredit" display="icon" />
                                        </h:panelGrid>
                                                                                
                                        <h:outputLabel value= "#{bundle.description}" /><h:outputLabel value=":"/>
                                        <p:inputTextarea autoResize="false" rows="1" cols="40" value="#{jvBean.unsaveDetail.description}" />
                                        
                                    </h:panelGrid>
                                    
                                    <h:panelGrid cellpadding="0" >
                                        <f:facet name="footer">  
                                            <p:commandButton value="Back" icon="ui-icon ui-icon-arrowthick-1-w" process="@this">
                                                <pe:resetEditableValues for="frmJV"/>  
                                                <pe:selectDetailLevel step="-1"/>
                                            </p:commandButton>
                                            
                                            <p:commandButton value="#{bundle.btnSave}" icon="ui-icon-disk" actionListener="#{jvBean.saveDetail()}" update="dtJvdetails"/>
                                            
                                            <p:commandButton value="#{bundle.btnNew}" icon="ui-icon-document" actionListener="#{jvBean.newDetail()}"  
                                                             process="@this" update="frmJV">
                                                <pe:resetEditableValues for="frmJV"/>  
                                            </p:commandButton>  
                                            
                                        </f:facet>
                                    </h:panelGrid>
                                    
                                </pe:masterDetailLevel>
                            </pe:masterDetail>
                        </p:panel>
                            
                    </h:panelGrid>    
                </h:panelGrid>
                
            </h:form>
        </ui:composition>
    </h:body>
</html>